package process0.grammar;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.CharStream;
import org.antlr.runtime.CommonTokenStream;
import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.TokenStream;
import org.antlr.runtime.tree.CommonTree;
import org.antlr.runtime.tree.CommonTreeNodeStream;

import process0.gen.Process0Lexer;
import process0.gen.Process0Parser;
import process0.gen.Process0Parser.process_return;
import process0.gen.Process0Walker;


public class TestProcessAST {

	public static void main(String[] args) throws RecognitionException {
		
		CharStream charStream = new ANTLRStringStream("process scrum {\n"
				+ "	workflow task{\n" + "a { b,c->d }\n" + "}\n"
				+ "	workflow bug{\n" + "		a { b,c->d r,o->q } \n"
				+ "		e {g,h->k \n" + "	}\n" + "}}");
		Process0Lexer lexer = new Process0Lexer(charStream);
		TokenStream tockenStream = new CommonTokenStream(lexer);
		Process0Parser parser = new Process0Parser(tockenStream);
		process_return evaluator = parser.process();
		System.out.println(((CommonTree) (evaluator.getTree())).toStringTree());
		CommonTreeNodeStream stream = new CommonTreeNodeStream(
				evaluator.getTree());
		Process0Walker walker = new Process0Walker(stream);
		String result = walker.process();
		System.out.println("ok \n" + result);
		try {
			PrintWriter out = new PrintWriter(new FileWriter("process.ini"));
			out.println(result);
			out.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

//		CommonTreeNodeStream stream2 = new CommonTreeNodeStream(
//				evaluator.getTree());
//		VisEvaluatorWalker walker2 = new VisEvaluatorWalker(stream2);
//		System.out.println(walker2.evaluator());
	}
}
